package com.zdsoft.finance.product.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zdsoft.finance.base.service.impl.BaseServiceImpl;
import com.zdsoft.finance.common.base.CustomRepository;
import com.zdsoft.finance.common.exception.BusinessException;
import com.zdsoft.finance.product.entity.Product;
import com.zdsoft.finance.product.repository.ProductRepository;
import com.zdsoft.finance.product.service.ProductService;

/**
 * 产品操作仓库实现
 * @author longwei
 * @date 2016/11/22
 * @version 1.0
 */
@Service("productService")
public class ProductServiceImpl extends BaseServiceImpl<Product, CustomRepository<Product,String>> implements ProductService{

	@Autowired
	private ProductRepository productRepository;
	
	@Override
	public Product findByCode(String code) {
		return productRepository.findByCode(code);
	}

	@Override
	public Page<Product> findByProduct(Product product,Pageable pageable) throws BusinessException {
		return productRepository.findByProduct(product, pageable);
	}

	@Override
	@Transactional
	public Product testTransacationalSave(Product product) {
		return productRepository.save(product);
	}

	@Override
	public Product testSave(Product product) {
		return productRepository.save(product);
	}

	@Override
	public Product testFind(Product product) {
		Product queryProduct=productRepository.findByCode(product.getCode());
		BeanUtils.copyProperties(product, queryProduct, new String[]{"id"});
		return productRepository.updateEntity(queryProduct);
	}

}
